﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RiskBlockMap.aspx.cs" Inherits="SkWeb.RiskDB.RiskBlockMap" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html{width: 100%;height: 100%;overflow: hidden;margin:0;}
#allmap {margin-right: 300px;height: 100%;overflow: hidden;}
#result {border-left:1px dotted #999;height:100%;width:295px;position:absolute;top:0px;right:0px;font-size:12px;}
dl,dt,dd,ul,li{
    margin:0;
    padding:0;
    list-style:none;
}
p{font-size:12px;}
dt{
    font-size:14px;
    font-family:"微软雅黑";
    font-weight:bold;
    border-bottom:1px dotted #000;
    padding:5px 0 5px 5px;
    margin:5px 0;
}
dd{
    padding:5px 0 0 5px;
}
li{
    line-height:28px;
}
</style>


<script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=C336a313e2012dcbe7d5994e09729dbd"></script>
<!--加载鼠标绘制工具-->
<script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
<link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" />

 <script src="../js/jquery-1.8.3.js" type="text/javascript"></script>
 <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script>
 <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" />

<title></title>
</head>
<body>
<form runat="server">
    <asp:Image ID="Image1" runat="server" />
    </form>
   <div id="allmap" style="overflow:hidden;zoom:1;position:relative;">	
    <div id="map" style="height:100%;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;"></div>
    <div id="showPanelBtn" style="position:absolute;font-size:14px;top:50%;margin-top:-95px;right:0px;width:20px;padding:10px 10px;color:#999;cursor:pointer;text-align:center;height:170px;background:rgba(255,255,255,0.9);-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;font-family:'微软雅黑';font-weight:bold;">显示检索结果面板<br/>&lt;</div>
    <div id="panelWrap" style="width:0px;position:absolute;top:0px;right:0px;height:100%;overflow:auto;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;">
        <div style="width:20px;height:200px;margin:-100px 0 0 -10px;color:#999;position:absolute;opacity:0.5;top:50%;left:50%;" id="showOverlayInfo">此处用于展示覆盖物信息</div>
        <div id="panel" style="position:absolute;"></div>
    </div>
</div>

<div id="result">
    <dl>
    	<dt>绘制工具功能</dt>
        <dd>
            <ul>
                <li><label><input type="radio" name="openClose1" onclick="drawingManager.open()"/>打开</label>  <label><input type="radio" name="openClose1" onclick="drawingManager.close()" checked="checked"/>关闭</label></li>
            </ul>
        </dd>
    	<dt>选择危险级别</dt>
        <dd>
            <ul>
              <!--  <li><label><input type="radio" name="openClose" onclick="drawingManager.enableCalculate()"/>打开</label>  <label><input type="radio" name="openClose" onclick="drawingManager.disableCalculate()"  checked="checked"/>关闭</label></li>-->
			  <li>
                    <label><input type="radio" name="drawmode" onclick="setClass(1)" checked="checked"/>一级风险</label>
                </li>
                <li>
                    <label><input type="radio" name="drawmode" onclick="setClass(2)"/>二级风险</label>
                </li>
				 <li>
                    <label><input type="radio" name="drawmode" onclick="setClass(3)"/>三级风险</label>
                </li>
				
				
				
            </ul>
        </dd>
    	<dt>绘制功能</dt>
        <dd>
            <ul>
                <li>
                    <label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_MARKER)" checked="checked"/>画点</label>
                    <input type="checkbox" id="isInfowindow"/> 是否带信息窗口
                </li>
                <li>
                    <label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_CIRCLE)"/>画圆</label>
                </li>
                <li>
                    <label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_POLYLINE)"/>画线</label>
                </li>
                <li>
                    <label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_POLYGON)"/>画多边形</label>
                </li>
                <li>
                    <label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_RECTANGLE)"/>画矩形</label>
                </li>
            </ul>
        </dd>
    	<dt>覆盖物操作</dt>
        <dd>
            <ul>
                <li>
                    <input type="button" value="获取绘制的覆盖物个数" onclick="alert(overlays.length)"/>
                    <input type="button" value="清除所有覆盖物" onclick="clearAll()"/>
                    <input type="button" value="获取最后一个覆盖物信息" id="getLastOverLay"/>
					<input type="button" value="保存" onclick="savaPath()"/>
                </li>
            </ul>
        </dd>
    </dl>

</div>

<script type="text/javascript">

    // 百度地图API功能

    var selObj = null;//用户当前选中的风险区块多边形
    var selRank = "first"; //当前选中区块的危险级别
    var selId = null;

    var map = new BMap.Map("map", { mapType: BMAP_HYBRID_MAP }); 
    var poi = new BMap.Point(125.028, 46.561);
    map.centerAndZoom(poi, 14);
    map.enableScrollWheelZoom();

    document.getElementById("getLastOverLay").onclick = function () {
        if (overlays.length) {
            alert(overlays[overlays.length - 1][0]);
        } else {
            alert("没有覆盖物");
        }
    }

    var ShapesInfo = [];
    function DrawShapes(data) {
        for (var i = 0; i < data.length; i++) {

            if (data[i].TYPE == "polygon") {
                var points = null;
                points = eval('[' + data[i].DATA + ']');
                var BPoints = [];
                for (var j = 0; j < points.length; j += 2) {
                    BPoints.push(new BMap.Point(points[j], points[j+1]));
                }
                var color = "";
                if (data[i].RANK == 1) {
                    color = "red";
                } else if (data[i].RANK == 2) {
                    color = "orange"; //橙色
                } else if (data[i].RANK == 3) {
                    color = "yellow";//黄色
                }

                var polygon = new BMap.Polygon(BPoints,
                    { strokeColor: color, strokeWeight: 3, strokeOpacity: 1 , fillColor: color,fillOpacity:0.7});
                ShapesInfo.push([polygon, data[i].ID,data[i].RANK]);
                map.addOverlay(polygon);
                polygon.addEventListener('click', OnPolygonClick);

            }
        }
    
    }

    var OnPolygonClick = function (event) {
        selObj = event.target;
        selId = ShapesInfo[i][1];
        for (var i = 0; i < ShapesInfo.length; i++) {
            if (selObj == ShapesInfo[i][0]) {
                if (ShapesInfo[i][2] == 1) {
                    selRank = "first";
                }
                else if (ShapesInfo[i][2] == 2) {
                    selRank = "second";
                }
                else if (ShapesInfo[i][2] == 3) {
                    selRank = "third";
                }
                break;
            }
        }

        searchInfoWindow.open(event.point);
        $("#fx").val(selRank);
    };


    var SavedShapeData = null;
    $.ajax({
        url: "Handler.ashx?op=getall",
        type: "post",
        data: '',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            // Play with returned data in JSON format
            SavedShapeData = data;
            DrawShapes(data);
        },
        error: function (msg) {
            alert('识别完成！');
        }
    });



    //信息窗口的内容定义
    //var content = '';
    var rank = 1;
    var overlays = [];
    //回调获得覆盖物信息


    var overlaycomplete = function (e) {
        overlays.push([e.overlay, rank, e.drawingMode]);
        var result = "";
        result = "<p>";
        result += e.drawingMode + ":";
        if (e.drawingMode == BMAP_DRAWING_MARKER) {
            result += ' 坐标：' + e.overlay.getPosition().lng + ',' + e.overlay.getPosition().lat;
            if (document.getElementById('isInfowindow').checked) {
                searchInfoWindow.open(e.overlay);
            }
        }
        if (e.drawingMode == BMAP_DRAWING_CIRCLE) {
            result += ' 半径：' + e.overlay.getRadius();
            result += ' 中心点：' + e.overlay.getCenter().lng + "," + e.overlay.getCenter().lat;
           

        }
        if (e.drawingMode == BMAP_DRAWING_POLYLINE || e.drawingMode == BMAP_DRAWING_POLYGON || e.drawingMode == BMAP_DRAWING_RECTANGLE) {
            result += ' 所画的点个数：' + e.overlay.getPath();
        }
        result += "</p>";
        document.getElementById("showOverlayInfo").style.display = "none";
        document.getElementById("panel").innerHTML += result; //将绘制的覆盖物信息结果输出到结果面板
    };


    var circlecomplete = function (cirObj) {
        cirObj.addEventListener("click", function (e) {
            searchInfoWindow.open(cirObj.getCenter());
            selObj = cirObj;
            //map.openInfoWindow(infoWindow, cirObj.getCenter());      // 打开信息窗口
        });
    }

    var styleOptions = {
        strokeColor: "red",    //边线颜色。
        fillColor: "red",      //填充颜色。当参数为空时，圆形将没有填充效果。
        strokeWeight: 3,       //边线的宽度，以像素为单位。
        strokeOpacity: 1,    //边线透明度，取值范围0 - 1。
        fillOpacity: 0.7,      //填充的透明度，取值范围0 - 1。
        strokeStyle: 'solid' //边线的样式，solid或dashed。
    }


    //实例化鼠标绘制工具
    var drawingManager = new BMapLib.DrawingManager(map, {
        isOpen: false, //是否开启绘制模式
        enableDrawingTool: true, //是否显示工具栏
        drawingToolOptions: {
            anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
            offset: new BMap.Size(5, 5), //偏离值
            scale: 0.8 //工具栏缩放比例
        },
        circleOptions: styleOptions, //圆的样式
        polylineOptions: styleOptions, //线的样式
        polygonOptions: styleOptions, //多边形的样式
        rectangleOptions: styleOptions //矩形的样式
    });

    var OnInfoSave = function () {
        var fx = $('#fx').val();
        var desc = $('#desc').val();
    };
    var OnInfoDelete = function () {
        map.removeOverlay(selObj);
        searchInfoWindow.close();
        selObj = null;
        if (selId != null) {
            
        }

    };
    var OnInfoCancel = function () {
        searchInfoWindow.close();
        selObj = null;
    };

    var content = '<div style="margin:0;line-height:20px;padding:2px;font-size:15px">' +
                    '设置风险级别：<select id="fx"> <option value ="first">一级风险</option> <option value ="second">二级风险</option> <option value="third">三级风险</option></select> ' +
                    '<br/>风险区块信息：'+
                    '<textarea id="desc" rows="5" cols="23"></textarea>' +
                    '<br/>&nbsp&nbsp<input type="button" onclick="OnInfoSave()" value="保存" />&nbsp&nbsp<input type="button"  onclick="OnInfoCancel()" value="取消" />&nbsp&nbsp<input type="button" onclick="OnInfoDelete()" value="删除" /> ' +
                  '</div>';

    //创建检索信息窗口对象
    var searchInfoWindow = null;
    searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
        title: "风险区块",      //标题
        width: 180,             //宽度
        height: 205,              //高度
        enableAutoPan: false,      //自动平移
        enableSendToPhone: false, //是否启用发送到手机
        searchTypes: []

    });



    //添加鼠标绘制工具监听事件，用于获取绘制结果
    drawingManager.addEventListener('overlaycomplete', overlaycomplete);
    drawingManager.addEventListener('circlecomplete', circlecomplete);

    function setClass(num) {
        rank = num;
        switch (num) {
            case 1:
                styleOptions = {
                    strokeColor: "red",    //边线颜色。
                    fillColor: "red",      //填充颜色。当参数为空时，圆形将没有填充效果。
                    strokeWeight: 3,       //边线的宽度，以像素为单位。
                    strokeOpacity: 1,    //边线透明度，取值范围0 - 1。
                    fillOpacity: 0.7,      //填充的透明度，取值范围0 - 1。
                    strokeStyle: 'solid' //边线的样式，solid或dashed。
                }
                break;
            case 2:
                styleOptions = {
                    strokeColor: "orange",    //边线颜色。
                    fillColor: "orange",      //填充颜色。当参数为空时，圆形将没有填充效果。
                    strokeWeight: 3,       //边线的宽度，以像素为单位。
                    strokeOpacity: 1,    //边线透明度，取值范围0 - 1。
                    fillOpacity: 0.7,      //填充的透明度，取值范围0 - 1。
                    strokeStyle: 'solid' //边线的样式，solid或dashed。
                }
                break;
            case 3:
                styleOptions = {
                    strokeColor: "yellow",    //边线颜色。
                    fillColor: "yellow",      //填充颜色。当参数为空时，圆形将没有填充效果。
                    strokeWeight: 3,       //边线的宽度，以像素为单位。
                    strokeOpacity: 1,    //边线透明度，取值范围0 - 1。
                    fillOpacity: 0.7,      //填充的透明度，取值范围0 - 1。
                    strokeStyle: 'solid' //边线的样式，solid或dashed。
                }
                break;

        }
        drawingManager = new BMapLib.DrawingManager(map, {
            isOpen: true, //是否开启绘制模式
            enableDrawingTool: true, //是否显示工具栏
            drawingToolOptions: {
                anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
                offset: new BMap.Size(5, 5), //偏离值
                scale: 0.8 //工具栏缩放比例
            },
            circleOptions: styleOptions, //圆的样式
            polylineOptions: styleOptions, //线的样式
            polygonOptions: styleOptions, //多边形的样式
            rectangleOptions: styleOptions //矩形的样式
        });
        //drawingManager.addEventListener('overlaycomplete', overlaycomplete);
    }



//    function $(id) {
//        return document.getElementById(id);
//    }

    function clearAll() {
        for (var i = 0; i < overlays.length; i++) {
            map.removeOverlay(overlays[i][0]);
        }
        overlays.length = 0
    }

    var isPanelShow = false;
    //显示结果面板动作
    document.getElementById("showPanelBtn").onclick = showPanel;
    function showPanel() {
        if (isPanelShow == false) {
            isPanelShow = true;
            document.getElementById("showPanelBtn").style.right = "230px";
            document.getElementById("panelWrap").style.width = "230px";
            document.getElementById("map").style.marginRight = "230px";
            document.getElementById("showPanelBtn").innerHTML = "隐藏绘制结果信息<br/>>";
        } else {
            isPanelShow = false;
            document.getElementById("showPanelBtn").style.right = "0px";
            document.getElementById("panelWrap").style.width = "0px";
            document.getElementById("map").style.marginRight = "0px";
            document.getElementById("showPanelBtn").innerHTML = "显示绘制结果信息<br/><";
        }
    }


    function savaPath() {
        var arr = [];
        for (var i = 0; i < overlays.length; i++) {
            if (overlays[i][2] == BMAP_DRAWING_POLYLINE || overlays[i][2] == BMAP_DRAWING_POLYGON || overlays[i][2] == BMAP_DRAWING_RECTANGLE)
                arr.push({ data: overlays[i][0].getPath(), rank: overlays[i][1], type: overlays[i][2] });
        }
        var str = JSON.stringify(arr);


        $.ajax({
            url: "Handler.ashx?op=SaveRiskBlockInfo",
            type: "post",
            data: str,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                // Play with returned data in JSON format
                //alter('保存成功！');

            },
            error: function (msg) {
                alert('保存成功！');
            }
        });


    }

   
    

	
</script>

   
</body>
</html>
